<?php
class Api_Row_Product extends Zend_Db_Table_Row_Abstract {
	public $inCartQuantity;
	
	public function init() {
		$this->inCartQuantity = $this->_table->getManager ()->Cart->getQuantity ( $this );
	}
	public function getListImg() {
		return '/image/product/170/' . $this->img_src . '.jpg';
	}
	public function getLitImg() {
		return '/image/product/45/' . $this->img_src . '.jpg';
	}
	public function isNew() {
		return ( bool ) $this->is_new;
	}
	public function isSpecial() {
		return ( bool ) $this->is_special;
	}
	public function isDiscount() {
		return ( bool ) $this->is_discount;
	}
	public function isInStock() {
		return isset ( $this->quantity ) ? ( bool ) $this->quantity : null;
	}
	public function setImages(Zend_Db_Table_Rowset $images) {
		$this->_data ['images'] = $images;
	}
	public function getUrl($reset = true, $encode = true) {
		return Zend_Controller_Front::getInstance ()->getRouter ()->assemble ( array ("controller" => "productlist", "action" => "details", "product" => $this->id ), null, $reset, $encode );
	}
	public function getInPack() {
		if (is_null ( $this->in_pack ))
			return null;
		$t = Zend_Registry::get ( 'Zend_Translate' );
		return /*sprintf(strtr($t->_('product in pack'), '#d', '%d'), (int)*/$this->in_pack; //);	
	}
	public function getMeter() {
		if (is_null ( $this->meter ))
			return null;
		$t = Zend_Registry::get ( 'Zend_Translate' );
		return $this->meter . $t->_ ( 'product centimeter' );
	}
	public function getPrice($type = true) {
		if (! isset ( $this->price ))
			return null;
		
		$res = ( string ) new Zend_Currency ( array ('locale' => 'en_US', 'format' => "#,##0.##0", 'value' => $this->price, 'display' => Zend_Currency::USE_SHORTNAME ) );
		
		list ( $int, $fract ) = explode ( '.', $res );
		$class = $type ? '' : ' mini';
		return '<span class="price-wrapper' . $class . '">' . strtr ( $int, ',', ' ' ) . sprintf ( '<sup>%s</sup>', $fract ) . '</span>';
	}
	
	public function getBuyButton() {
		$str = ($this->inCartQuantity === 0) ? 'empty' : 'full';
		return '<div prod-id="' . $this->id . '" class="add-to-cart ' . $str . '"></div>';
	}
}